import React, { useCallback } from "react"
import { Field_FormSave, Field_name_id } from "@/components/utils/field.list"
import { FormProps } from "@/components/modal/form.modal"
import { FormRender } from "@whzhuke/antd"
import useForm from "antd/es/form/hooks/useForm"
import orderService from "@/services/order.service"

interface Props {
  values?: any
}
export const EditOrders: React.FC<Props & FormProps> = props => {
  const { values, onDone } = props
  const [form] = useForm<any>()
  const onFinish = useCallback(
    data => {
      const payload = {
        ...data,
        payTime: data.payTime ? new Date(data.payTime).getTime() : undefined
      }
      orderService[values ? "edit" : "save"](payload).then(() => {
        onDone?.()
      })
    },
    [values, onDone]
  )

  return (
    <FormRender
      form={form}
      initialValues={
        values
          ? {
              ...values
            }
          : {}
      }
      layout="horizontal"
      preserve={false}
      onFinish={onFinish}
      labelCol={{ span: 8 }}
      wrapperCol={{ span: 16 }}
      style={{ width: 600 }}
      fieldList={[
        values ? Field_name_id : undefined,
        {
          fieldType: "select",
          formItemConfig: { required: !0, name: "status", label: "订单状态" },
          config: {
            placeholder: "订单状态",
            options: [
              { label: "待付款", value: 0 },
              { label: "待发货", value: 1 },
              { label: "待收货", value: 2 },
              { label: "已取消", value: 3 },
              { label: "已完成", value: 4 }
            ]
          }
        },
        {
          fieldType: "select",
          formItemConfig: { required: !0, name: "pickinstoreType", label: "是否门店自提" },
          config: {
            placeholder: "是否门店自提",
            options: [
              { label: "否", value: 0 },
              { label: "是", value: 1 }
            ]
          }
        },
        {
          fieldType: "select",
          formItemConfig: { required: !0, name: "payStatus", label: "支付状态" },
          config: {
            placeholder: "支付状态",
            options: [
              { label: "未支付", value: 0 },
              { label: "已支付", value: 1 }
            ]
          }
        },
        {
          fieldType: "select",
          formItemConfig: { required: !0, name: "logisticsStatus", label: "发货状态" },
          config: {
            placeholder: "订单状态",
            options: [
              { label: "未发货", value: 0 },
              { label: "已发货", value: 1 },
              { label: "部分发货", value: 2 }
            ]
          }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "logisticsTime", label: "最新发货时间" },
          config: { placeholder: "最新发货时间" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "logisticsName", label: "物流名称" },
          config: { placeholder: "物流名称" }
        },
        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "logisticsNo", label: "物流单号" },
          config: { placeholder: "物流单号" }
        },
        {
          fieldType: "select",
          formItemConfig: { required: !0, name: "payCode", label: "支付类型" },
          config: {
            placeholder: "支付类型",
            options: [
              { label: "微信", value: 1 },
              { label: "支付宝", value: 2 },
              { label: "账户余额", value: 3 },
              { label: "货到付款", value: 4 },
              { label: "现金支付", value: 5 }
            ]
          }
        },

        {
          fieldType: "input",
          formItemConfig: { required: !0, name: "payName", label: "支付方式名称" },
          config: { placeholder: "支付方式名称" }
        },
        {
          fieldType: "date",
          formItemConfig: { required: !0, name: "payTime", label: "支付时间" },
          config: {
            showTime: !0,
            format: "YYYY-MM-DD HH:mm:ss"
          }
        },

        { ...Field_FormSave, formItemConfig: { wrapperCol: { offset: 8, span: 16 } } }
      ]}
      autoComplete="off"
    />
  )
}
